<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Areas_m extends FOX_Model
{

	function __construct ()
	{
		parent::__construct();
	}

    /**
     * @param $area_id
     * @return mixed
     * 查询单条
     */
    public function get_area_by_id($area_id){
        $query = $this->db
            ->select('*')
            ->get_where('areas', array('area_id'=>$area_id));
        return $query->row_array();
    }


    /**
     * @param $pid 为 1 时 获取全国的省
     * @return mixed
     * 获取所有子集
     */
    public function get_sons_by_pid($pid = 1){
        $this->db->select('*');
        $this->db->from('areas');
        $this->db->where('parent_id',$pid);
        $this->db->where('deleted',0);
        $query = $this->db->get();
        if($query->num_rows() > 0){
            return $query->result_array();
        }
    }

    /**
     * @param $where
     * @return bool
     * 删除商家
     */
    public function delete_shop_users_by($where){
        $this->db->where($where)->delete('areas');
        return ($this->db->affected_rows() > 0) ? TRUE : FALSE;
    }

    /**
     * @param $pid 为 1 时 获取全国的省
     * @return mixed
     * 获取所有子集
     */
    public function get_sons_by_type($area_type){
        $this->db->select('*');
        $this->db->from('areas');
        $this->db->where('area_type',$area_type);
        $this->db->where('deleted',0);
        $query = $this->db->get();
        if($query->num_rows() > 0){
            return $query->result_array();
        }
    }
    public function get_area_name_by_id($id){
        $query = $this->db->select('area_name')->from('areas')->where('area_id',$id)->get();
        return $query->row_array();
    }

}
